import arcade
import random

SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600

arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, "Tree")
arcade.set_background_color((135, 206, 235, 255))


def draw_tree(center_x, center_y):
    arcade.draw_rectangle_filled(center_x, center_y - 15, 20, 60, arcade.csscolor.SIENNA)
    arcade.draw_triangle_filled(center_x - 30, center_y - 15,
                                center_x + 30, center_y - 15,
                                center_x, center_y + 60,
                                (1, 50, 32, 255))


def draw_bird(center_x, center_y, scale=1):
    width = 60 * scale  # scale用于调整翅膀大小
    # 左边翅膀
    arcade.draw_arc_outline(center_x - width / 2, center_y, width, width, arcade.color.BLACK, 0, 90, border_width=4)
    # 右边翅膀
    arcade.draw_arc_outline(center_x + width / 2, center_y, width, width, arcade.color.BLACK, 90, 180, border_width=4)


arcade.start_render()

# 绘制地面
arcade.draw_lrtb_rectangle_filled(0, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2, 0, (23, 114, 69, 255))

# 树宽70, 画树时从40开始，保证树叶与左边缘留有一点距离
start_x = 40
step = 80  # 树宽70, 每隔80点画一颗树
for i in range(7):
    # 第一排树
    draw_tree(start_x + step * i, SCREEN_HEIGHT / 2 + 30)
    # 第二排树
    draw_tree(start_x + 30 + step * i, SCREEN_HEIGHT / 2 - 60)
    # 随机生成x, y坐标
    bird_x = random.randint(60, SCREEN_HEIGHT - 60)
    bird_y = random.randint(SCREEN_HEIGHT / 2, SCREEN_HEIGHT - 60)
    # 大小系数控制在0.5~1之间
    scale = random.randrange(5, 10) / 10
    draw_bird(bird_x, bird_y, scale)

arcade.finish_render()

arcade.run()
